<?php
function execute($sql) {
	// Connecting, selecting database
	$link = mysql_connect ( 'localhost', 'root', 'stimpy' ) or die ( 'Could not connect: ' . mysql_error () );
	//echo 'Connected successfully';
	mysql_select_db ( 'go_search' ) or die ( 'Could not select database' );
	
	// Performing SQL query
	$query = $sql;
	$result = mysql_query ( $query ) or die ( 'Query failed: ' . mysql_error () );
	
	// Free resultset
	mysql_free_result ( $result );
	
	// Closing connection
	mysql_close ( $link );
	
	return "success";
}

/**
 * 
 * @param string $sql
 * @param array $column_array --- what columns does the sql query?
 * @return json record
 */
function query_json($sql) {
	$link = mysql_connect ( 'localhost', 'root', 'stimpy' ) or die ( 'Could not connect: ' . mysql_error () );
	
	mysql_select_db ( 'go_search' ) or die ( 'Could not select database' );
	
	// Performing SQL query
	$query = $sql;
	$result = mysql_query ( $query ) or die ( 'Query failed: ' . mysql_error () );
	
	$arr = array ();
	$line_num = 0;
	// Printing results into $arr
	while ( $line = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
		$arr [$line_num] = $line;
		$line_num ++;
	}
	
	// Free resultset
	mysql_free_result ( $result );
	
	// Closing connection
	mysql_close ( $link );
	return json_encode ( $arr );
}

/**
 * 
 * @param string $sql
 * @param array $column_array --- what columns does the sql query?
 * @return array record
 */
function query_array($sql) {
	$link = mysql_connect ( 'localhost', 'root', 'stimpy' ) or die ( 'Could not connect: ' . mysql_error () );
	
	mysql_select_db ( 'go_search' ) or die ( 'Could not select database' );
	
	// Performing SQL query
	$query = $sql;
	$result = mysql_query ( $query ) or die ( 'Query failed: ' . mysql_error () );
	
	$arr = array ();
	$line_num = 0;
	// Printing results into $arr
	while ( $line = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
		$arr [$line_num] = $line;
		$line_num ++;
	}
	
	// Free resultset
	mysql_free_result ( $result );
	
	// Closing connection
	mysql_close ( $link );
	return $arr;
}

?>
